const dirPath = './此文件夹放视频'
const fs = require('fs')
const readDir = fs.readdirSync(dirPath)
const ffprobe = require('ffprobe')
const ffprobeStatic = require('ffprobe-static')
const message = []
let totalDuration = 0
let count = 0
for (let i = 0; i < readDir.length; i++) {
    ffprobe(dirPath + '/' + readDir[i], {
        path: ffprobeStatic.path
    }).then((info) => {
        message[i] = {
            path: readDir[i],
            duration: info.streams[0].duration
        }
        totalDuration += parseFloat(info.streams[0].duration)
        count++
        if (count >= readDir.length) {
            totalDuration = Math.round(totalDuration)
            let hour = Math.floor(totalDuration / 3600)
            let minute = Math.round((totalDuration % 3600) / 60)
            console.log(message)
            console.log('共' + totalDuration + '秒，相当于' + hour + '小时' + minute + '分钟')
            console.log('共' + count + '个视频')
        }
    }).catch((err) => {
        console.log(err)
    })
}